function fallBlock() {
	this.x;
	this.y;
	this.arr = new Array();
};

fallBlock.prototype.begin = function() {
	this.x = 70;
	this.y = 37;
	this.stx;
	this.sty;
	this.ndx;
	this.ndy;
	this.stRow;
	this.stCol;
	this.ndRow;
	this.ndCol;
	this.dragable = true;
}

function nextBlock() {
	this.x = 227;
	this.y = 37;
	this.arr = new Array();
};

function getRan() { //随机取一个形状
	NO = Math.floor(Math.random() * 7);
	giveValue(lamda.arr, ran[NO]);

	var rot = Math.floor(Math.random() * 4);
	if (rot > 0) {
		for (var i = 0; i < rot; i++) {
			turnRight(lamda.arr);
		}
	}
	getTopLeft(lamda);
	moveLeftnTop(lamda);

	//旋转后移到四格的左上角
	if (checkIfI(lamda.arr)) {
		moveRight(lamda.arr); //如果是I型，向右移一格
	}
	giveValue(next.arr, lamda.arr);
}

function checkIfDead(obj) {
	for (var i = obj.ndRow; i >= obj.stRow; i--) {
		for (var j = obj.stCol; j <= obj.ndCol; j++) {
			if ((wstRow + i + 1) >= 0) {
				if ((fall.arr[i][j] == 1) && (wall.arr[wstRow + i + 1][wstCol + j] == 1)) { //dead
					printDeadBlock(fall); //把死block打印到墙上
					giveValue(fall.arr, next.arr); //生成新block
					getBottomRight(fall);
					getRan();
					fall.begin();
					fall.y -= fall.ndRow * 21;
					frame = 1;
					if (SHold == true) { //如果S键被hold住
						fall.dragable = false; //下一个不能被下拽
					}
					checkLine(); //检查墙上是否可消
					return;//一旦判断block死就跳出
				}
			}
		}
	}
}

function printDeadBlock(obj) {
	for (var i = obj.stRow; i <= obj.ndRow; i++) {
		for (var j = obj.stCol; j <= obj.ndCol; j++) {
			if (fall.arr[i][j] == 1) {
				if ((wstRow + i) >= 0) {
					wall.arr[wstRow + i][wstCol + j] = 1;
				}
			}
		}
	}
}

function blockFalling() {
	if (frame % shiftRan == 0) {
		fall.y += 21; //每隔一段时间下降一格
	}
	frame++;
}

function drawBlock(obj, alpha, gamma) { //画一个形状
	for (var i = 0; i < alpha; i++) {
		for (var j = 0; j < gamma; j++) {
			if (obj.arr[i][j] == 1) {
				//ctx.fillStyle = "rgba(12,145,145,0.5)";
				ctx.fillStyle = "#eaf2bc";
				ctx.fillRect(obj.x + j * 21, obj.y + i * 21, 19, 19);
				ctx.fill();
			}
		}
	}
}